package com.ims.core.doc.service.impl;

import java.util.List;
import com.ims.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ims.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ims.core.doc.domain.TInNon1016Entry;
import com.ims.core.doc.mapper.TInNon1016Mapper;
import com.ims.core.doc.domain.TInNon1016;
import com.ims.core.doc.service.ITInNon1016Service;

/**
 * 1016 航空运输电子客票行程单退改费  Service业务层处理
 *
 * @author IMS
 * @date 2024-12-01
 */
@Service
public class TInNon1016ServiceImpl implements ITInNon1016Service
{
    @Autowired
    private TInNon1016Mapper tInNon1016Mapper;

    /**
     * 查询1016 航空运输电子客票行程单退改费
     *
     * @param id 1016 航空运输电子客票行程单退改费  主键
     * @return 1016 航空运输电子客票行程单退改费
     */
    @Override
    public TInNon1016 selectTInNon1016ById(Long id)
    {
        return tInNon1016Mapper.selectTInNon1016ById(id);
    }

    /**
     * 查询1016 航空运输电子客票行程单退改费  列表
     *
     * @param tInNon1016 1016 航空运输电子客票行程单退改费
     * @return 1016 航空运输电子客票行程单退改费
     */
    @Override
    public List<TInNon1016> selectTInNon1016List(TInNon1016 tInNon1016)
    {
        return tInNon1016Mapper.selectTInNon1016List(tInNon1016);
    }

    /**
     * 新增1016 航空运输电子客票行程单退改费
     *
     * @param tInNon1016 1016 航空运输电子客票行程单退改费
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertTInNon1016(TInNon1016 tInNon1016)
    {
        tInNon1016.setCreateTime(DateUtils.getNowDate());
        int rows = tInNon1016Mapper.insertTInNon1016(tInNon1016);
        insertTInNon1016Entry(tInNon1016);
        return rows;
    }

    /**
     * 修改1016 航空运输电子客票行程单退改费
     *
     * @param tInNon1016 1016 航空运输电子客票行程单退改费
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateTInNon1016(TInNon1016 tInNon1016)
    {
        tInNon1016.setUpdateTime(DateUtils.getNowDate());
        tInNon1016Mapper.deleteTInNon1016EntryByInvoiceId(tInNon1016.getId());
        insertTInNon1016Entry(tInNon1016);
        return tInNon1016Mapper.updateTInNon1016(tInNon1016);
    }

    /**
     * 批量删除1016 航空运输电子客票行程单退改费
     *
     * @param ids 需要删除的1016 航空运输电子客票行程单退改费  主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteTInNon1016ByIds(Long[] ids)
    {
        tInNon1016Mapper.deleteTInNon1016EntryByInvoiceIds(ids);
        return tInNon1016Mapper.deleteTInNon1016ByIds(ids);
    }

    /**
     * 删除1016 航空运输电子客票行程单退改费  信息
     *
     * @param id 1016 航空运输电子客票行程单退改费  主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteTInNon1016ById(Long id)
    {
        tInNon1016Mapper.deleteTInNon1016EntryByInvoiceId(id);
        return tInNon1016Mapper.deleteTInNon1016ById(id);
    }

    /**
     * 新增1016 航空运输电子客票行程单退改费  信息
     *
     * @param tInNon1016 1016 航空运输电子客票行程单退改费  对象
     */
    public void insertTInNon1016Entry(TInNon1016 tInNon1016)
    {
        List<TInNon1016Entry> tInNon1016EntryList = tInNon1016.getTInNon1016EntryList();
        String invoiceId = tInNon1016.getInvoiceId();
        if (StringUtils.isNotNull(tInNon1016EntryList))
        {
            List<TInNon1016Entry> list = new ArrayList<TInNon1016Entry>();
            for (TInNon1016Entry tInNon1016Entry : tInNon1016EntryList)
            {
                tInNon1016Entry.setInvoiceId(invoiceId);
                list.add(tInNon1016Entry);
            }
            if (list.size() > 0)
            {
                tInNon1016Mapper.batchTInNon1016Entry(list);
            }
        }
    }
}
